﻿using System;
using System.Collections.Generic;
using System.Data.Entity;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using TpWeb.Domain.BizObj;
using TpWeb.Domain.Repositories;

namespace TpWeb.Dal.Repositories
{
    internal class ContactRepository : Repository<Contact, int>, IContactRepository
    {

        public ContactRepository(DbContext context)
            : base(context, null)
        {

        }


        private string NewPin(int id)
        {
            var cont = All.SingleOrDefault(c => c.Id == id);
            if (cont == null)
                return null;

            cont.Pin = Guid.NewGuid().ToString();

            Update(cont);

            return cont.Pin;
        }

        public bool CheckPin(int id, string pin)
        {
            var cont =All.SingleOrDefault(c => c.Id == id);

            if (cont == null || cont.Pin.ToLower()!= pin.ToLower())
            {
                cont.Pin = Guid.NewGuid().ToString();
                Update(cont);
                return false;
            }

            return true;
        }
    }
}
